//
//  ZYHelpCenterDetailVC.m
//  YiLin
//
//  Created by Zyark on 2018/6/11.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYHelpCenterDetailVC.h"
#import "UIButton+ImageTitleSpacing.h"

@interface ZYHelpCenterDetailVC ()
@property(nonatomic,strong) UILabel *problemLabel;
@property(nonatomic,strong) UILabel *contentLabel;
@property(nonatomic,strong) UIButton *operationBtn;
@end

@implementation ZYHelpCenterDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.title = [[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_ME_MAIN_HELP_CENTER];
}

#pragma mark - init
-(void)setup{
    [self setupView];
}

-(void)setupView{
    _problemLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W - 30, 30)];
    _problemLabel.textColor = kLabelColor;
    _problemLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:_problemLabel];
    _problemLabel.left = 15;
    _problemLabel.top = self.navigationView.bottom;
    _problemLabel.text = _problemTitle;
    _problemLabel.numberOfLines = 0;
    NSDictionary *problemAttributes = @{NSFontAttributeName:_problemLabel.font};
    CGSize problemTextSize = [_problemTitle boundingRectWithSize:CGSizeMake(_problemLabel.width, CGFLOAT_MAX)
                                                       options:NSStringDrawingUsesLineFragmentOrigin attributes:problemAttributes context:nil].size;
    _problemLabel.height = problemTextSize.height;
    
    _contentLabel = [[UILabel alloc] initWithFrame:_problemLabel.bounds];
    _contentLabel.textColor = RGBA(102, 102, 102, 1);
    _contentLabel.font = [UIFont systemFontOfSize:14];
    _contentLabel.numberOfLines = 0;
    [self.view addSubview:_contentLabel];
    _contentLabel.centerX = self.view.centerX;
    _contentLabel.top = _problemLabel.bottom + 15;
    NSString *content = @"";
    switch (_problemType) {
        case ZyProblemtypeInternetError:
            content = LC_HELP_CENTER_DETAIL_INTERNET_ERROR;
            break;
        case ZyProblemtypeDeviceError:
            content = LC_HELP_CENTER_DETAIL_DEVICE_ERROR;
            break;
        case ZyProblemtypeAPPError:
            content = LC_HELP_CENTER_DETAIL_APP_ERROR;
            break;
        default:
            break;
    }
    NSString *contentText = [[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:content];
//    _contentLabel.text = contentText;

    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.alignment = NSTextAlignmentLeft;  //对齐
    paraStyle.headIndent = 0.0f;//行首缩进
    //参数：（字体大小17号字乘以2，34f即首行空出两个字符）
    CGFloat emptylen = self.contentLabel.font.pointSize * 2;
    paraStyle.firstLineHeadIndent = emptylen;//首行缩进
    paraStyle.tailIndent = 0.0f;//行尾缩进
    paraStyle.lineSpacing = 8.0f;//行间距
    _contentLabel.attributedText = [[NSAttributedString alloc] initWithString:contentText attributes:@{NSParagraphStyleAttributeName:paraStyle}];
    NSDictionary *attributes = @{NSFontAttributeName:_contentLabel.font,NSParagraphStyleAttributeName:paraStyle};
    CGSize textSize = [contentText boundingRectWithSize:CGSizeMake(_contentLabel.width, CGFLOAT_MAX)
                                                options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
    _contentLabel.height = textSize.height;
    
    _operationBtn = [self setupButtonWithTitle:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_HELP_CENTER_DETAIL_BTN_OPERATION]];
    _operationBtn.top = _contentLabel.bottom + 40;
    _operationBtn.centerX = self.view.centerX;
}

-(UIButton *)setupButtonWithTitle:(NSString *)title{
    UIButton *button = [[UIButton alloc] init];
    button.size = CGSizeMake(75, 20);
    [self.view addSubview:button];
    [button setTitleColor:kMainColor forState:UIControlStateNormal];
    UIFont *buttonFont = [UIFont systemFontOfSize:12];
    [button.titleLabel setFont:buttonFont];
    [button setTitle:title forState:UIControlStateNormal];
    NSDictionary *attributes = @{NSFontAttributeName:buttonFont,};
    CGSize size = [title boundingRectWithSize:CGSizeMake(150, button.titleLabel.height)
                                      options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    button.width = size.width + 35;
    [button setImage:[UIImage imageNamed:@"ic_help_center_detail_tap"] forState:UIControlStateNormal];
    [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:11];
    return button;
}

@end
